import qs from 'qs'
import { callBackUrl, epecBaseUrl, gatewayBaseUrl, memberBaseUrl, runtimeConfig } from '~/utils/commonData'
import httpRequest from '../server/index'

interface RequestData {
  [key: string]: any // 适用于动态数据结构，可根据实际需求修改
}

const getImageCode = (data?: RequestData): Promise<any> => {
  const baseURL = epecBaseUrl(runtimeConfig())
  return httpRequest.post(`/sam/auth/imageCode.do`, data, {
    server: false,
    baseURL,
  })
}

const getPublicKey = (data?: RequestData): Promise<any> => {
  const baseURL = epecBaseUrl(runtimeConfig())
  return httpRequest.post(`/sam/auth/publicKey.do`, data, {
    server: false,
    baseURL,
  })
}

const samCookie = (data?: RequestData): Promise<any> => {
  const baseURL = epecBaseUrl(runtimeConfig())
  return httpRequest.post(`/sam/auth/samCookie.do`, data, {
    server: false,
    baseURL,
  })
}

const callbackForAjax = (data?: RequestData): Promise<any> => {
  const baseURL = gatewayBaseUrl(runtimeConfig())
  return httpRequest.get(`/ssoLogin/callbackForAjax?${qs.stringify(data)}`, {}, {
    server: false,
    credentials: 'include',
    baseURL,
  })
}
const getLoginInfo = (data?: RequestData): Promise<any> => {
  const baseURL = gatewayBaseUrl(runtimeConfig())
  return httpRequest.get(`/api/user-center/user/getLoginInfo`, data, {
    server: false,
    baseURL,
  })
}

const getMemberDomain = () => {
  const baseURL = memberBaseUrl(runtimeConfig())
  return baseURL
}

export { callbackForAjax, callBackUrl, getImageCode, getLoginInfo, getMemberDomain, getPublicKey, samCookie }
